//
//  GQJAutoreleaseController.m
//  TotalDemo
//
//  Created by gujian on 16/8/3.
//  Copyright © 2016年 gujian. All rights reserved.
//

#import "GQJAutoreleaseController.h"
#import "GQJCompareModel.h"
#import "GQJCompareModel+Category.h"

OBJC_EXTERN void _objc_autoreleasePoolPrint();

@interface GQJAutoreleaseController()<UIScrollViewDelegate>

@property (nonatomic, weak) UIScrollView *scrollView;

@end

@implementation GQJAutoreleaseController

__weak id reference = nil;

//http://blog.sunnyxx.com/2014/10/15/behind-autorelease/

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *str = [NSMutableString stringWithFormat:@"gujian"];
    reference = str;

    _objc_autoreleasePoolPrint();
    
    //验证调用私有方法，在category中声明私有方法即可
//    GQJCompareModel *model = [[GQJCompareModel alloc] init];
//    [model logInfo];
    
    [self initSubview];
}


- (void)initSubview
{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    scrollView.contentSize = CGSizeMake(scrollView.width, 1000);
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
     _objc_autoreleasePoolPrint();
    NSLog(@"%@",reference);
    
    //分歧点 autoreleasepool是在runloop迭代结束后释放还是在休眠时释放
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
     _objc_autoreleasePoolPrint();
    NSLog(@"%@",reference);
    
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    _objc_autoreleasePoolPrint();
}


#pragma mark - UIScrollView delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _objc_autoreleasePoolPrint();
    [NSRunLoop currentRunLoop];
}

@end
